package com.ytf.core.config;

import com.ytf.core.web.application.PermissionAppService;
import com.ytf.core.web.application.RoleAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * @author YTF
 * @className DataInitializer
 * @date 2025/5/28 16:12
 * @description
 */
@Slf4j
@Component
public class DataInitializer implements CommandLineRunner {

    private final RoleAppService roleAppService;
    private final PermissionAppService permissionAppService;

    public DataInitializer(RoleAppService roleAppService, PermissionAppService permissionAppService) {
        this.roleAppService = roleAppService;
        this.permissionAppService = permissionAppService;
    }

    @Override
    @Transactional
    public void run(String... args) {
        long startTime = System.currentTimeMillis();
        log.info("开始角色和权限加载...");
        // 加载权限
        permissionAppService.init();
        // 加载角色
        roleAppService.init();
        log.info("角色和权限加载完成... 用时："+(System.currentTimeMillis()-startTime));
    }

}